﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WindowsGame1.View
{
    class FireworksSystem
    {
        //fält
        private const int   NUM_PARTICLES = 100;
        Fireworks[]         _particles = new Fireworks[NUM_PARTICLES];

        //konstruktor
        public FireworksSystem() 
        {
            Random rand = new Random(10);

            Vector2 pos = new Vector2(0, 0);

            float speed = 10.0f;
            for (int i = 0; i < NUM_PARTICLES; i++)
            {
                Vector2 velocity = new Vector2((2.0f * (float)rand.NextDouble() - 1.0f),
                                               (2.0f * (float)rand.NextDouble() - 1.0f));

                velocity.Normalize(); //sätt längden

                velocity *= speed * (float)rand.NextDouble();

                _particles[i] = new Fireworks(pos, velocity);
            }
        }

        //metod för att rita ut partiklarna
        internal void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch a_spriteBatch, Microsoft.Xna.Framework.Graphics.Texture2D a_sparkTexture, float a_elapsedTime)
        {
            for (int i = 0; i < NUM_PARTICLES; i++)
            {
                _particles[i].Update(a_elapsedTime / 10.0f);

                Vector2 modelPosition = _particles[i].GetPosition();

                Vector2 viewPos = modelPosition * 100.0f + new Vector2(400, 300);
                int particleViewSize = 25;

                Rectangle destinationRectangle = new Rectangle((int)viewPos.X - particleViewSize / 2, (int)viewPos.Y - particleViewSize / 2, particleViewSize, particleViewSize);
                a_spriteBatch.Draw(a_sparkTexture, destinationRectangle, Color.White);
            }
        }
    }
}
